package be.jprojects.subscription.gui.tablepanels;

import java.util.List;

import javax.swing.JFrame;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;

import be.jprojects.subscription.controllers.ListenersController;
import be.jprojects.subscription.gui.datamodels.HideColumnDataModel;
import be.jprojects.subscription.gui.datamodels.PersonDataModel;
import be.jprojects.subscription.logic.BusinessLogicController;
import be.jprojects.subscription.logic.interfaces.IPerson;


public class PersonTablePanel extends TablePanel {
	private JFrame frame;
	
	private List<IPerson> persons;
	public PersonTablePanel(JFrame frame) {
		super("Person");
		this.frame = frame;

		setEnabled(false);
		persons = null;
		try {
			persons = BusinessLogicController.getInstance().getPersons();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		HideColumnDataModel dataModel = new PersonDataModel(persons);
		
		table.setModel(dataModel);
	}

	@Override
	public void selectedIndexChanged(int index) {
		ListenersController.getInstance().selectedPersonChanged(persons.get(index));
	}

	@Override
	public void deleteActionPerformed() {
		setSelectable(false);
	}

	@Override
	public void newActionPerformed() {
		ListenersController.getInstance().selectedPersonChanged(null);
		setSelectable(false);
	}

	@Override
	public void updateActionPerformed() {
		setSelectable(false);
	}
	
	@Override
	public void saveActionPerformed() {
		setSelectable(true);
	}

	@Override
	public void cancelActionPerformed() {
		setSelectable(true);
	}
}
